package learn.hibernate.service.impl;

import java.util.HashSet;
import java.util.Set;

import org.apache.tools.ant.taskdefs.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import learn.hibernate.bean.po.PoResource;
import learn.hibernate.bean.po.PoRole;
import learn.hibernate.dao.RoleDaoI;
import learn.hibernate.service.RoleServiceI;


@Service
public class RoleServiceImpl implements RoleServiceI {

	@Autowired
	private RoleDaoI roleDao;
	
	@Override
	public void saveRoleWithResource(){
		PoRole role=new PoRole();
		role.setName("L2");
		PoResource poResource=new PoResource();
		poResource.setName("r2");
		role.getResourceList().add(poResource);
		roleDao.save(role);
	}
	

	@Override
	public void deleteRoleByDao(int id){
		PoRole role=roleDao.get(PoRole.class, id);
		roleDao.delete(role);
	}
	
	@Override
	public void deleteRoleByHql(){
		String hql="delete from PoRole";
		roleDao.executeHql(hql);
	}
	
	
	@Override
	public void updateRoleWithResource(int id){
		/*String hql="delete from PoRole";
		roleDao.executeHql(hql);*/
		PoRole role=roleDao.get(PoRole.class, id);
		role.setName("L update in role");
		role.getResourceList().get(0).setName("R update in role");
		roleDao.update(role);
	}
}
